"""
A class to exercise the JT core functions.
"""
import itk
import vtk
import JT
import Calibration
from numpy import array

def Test():
    """
    Test putting an object in front of a background image in a render window
    """

    imageFile= 'C:/Users/bryan/bryan-code/2D3D/vert1/fluoro/ushortim080-LAT.mha'

    #
    # Create Rendering components
    #%###########################
    renWin = vtk.vtkRenderWindow()
    renWin.SetNumberOfLayers(2)

    ren1 = vtk.vtkRenderer()
    renWin.AddRenderer(ren1)
    ren1.SetInteractive(1)
    ren1.SetLayer(1)

    imageRen = vtk.vtkRenderer()
    renWin.AddRenderer(imageRen)
    imageRen.SetInteractive(0)
    imageRen.SetLayer(0)

    renWin.SetSize(512, 512)

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)


    #
    # Create Cone
    #%###########################
    cone = vtk.vtkConeSource()
    cone.SetHeight( 3.0 )
    cone.SetRadius( 1.0 )
    cone.SetResolution( 10 )

    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())

    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    ren1.AddActor(coneActor)

    #
    # Read Background Image
    #%##########################

    imageMapper = vtk.vtkImageMapper()
    imageActor = vtk.vtkActor2D()
    reader = vtk.vtkMetaImageReader()

    imageActor.SetMapper(imageMapper)
    imageRen.AddActor2D(imageActor)

    reader.SetFileName(imageFile)
    reader.Update()
    backgroundImage = reader.GetOutput()

    #
    # Set Background Image
    #%##########################
    imageMapper.SetInput(backgroundImage)

    (minPixel, maxPixel) = backgroundImage.GetScalarRange()

    imageMapper.SetColorLevel(maxPixel/2)
    imageMapper.SetColorWindow(maxPixel)

    renWin.Render()
    iren.Start()


if __name__ == "__main__":
    Test()